package com.sh.sales.happysales.adapter;

import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.sh.sales.happysales.R;


/**
 * Created by zhouyucheng on 2017/9/15.
 */

public class MineMenuAdapter extends BaseAdapter {
    private String[] strMenus;
    private int[] imgMenus;
    private Context mContext;

    public MineMenuAdapter(String[] strMenus, int[] imgMenus, FragmentActivity activity) {
        this.strMenus = strMenus;
        this.imgMenus = imgMenus;
        this.mContext = activity;
    }

    public void MineMenuAdapter(String[] strMenus, int[] imgMenus, Context mContext) {
        this.imgMenus = imgMenus;
        this.mContext = mContext;
        this.strMenus = strMenus;
    }

    @Override
    public int getCount() {
        return strMenus.length;
    }

    @Override
    public Object getItem(int i) {
        return strMenus[i];
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        MenuHolder mMenuHolder = null;
        if (view == null) {
            mMenuHolder = new MenuHolder();
            view = LayoutInflater.from(mContext).inflate(R.layout.item_minmenu, null);
            mMenuHolder.menuImage = (ImageView) view.findViewById(R.id.icon_menulogo);
            mMenuHolder.nenuText = (TextView) view.findViewById(R.id.icon_menuname);
            view.setTag(mMenuHolder);
        } else {
            mMenuHolder = (MenuHolder) view.getTag();
        }
        mMenuHolder.menuImage.setImageResource(imgMenus[i]);
        mMenuHolder.nenuText.setText(strMenus[i]);
        return view;
    }

    class MenuHolder {
        ImageView menuImage;
        TextView nenuText;
    }
}
